﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RedHouse.Web.common;
using RedHouse.Data.Entities;
using RedHouse.Data.Base;
using RedHouse.Data.Common;
using RedHouse.Data;
using RedHouse.Data.Service;

namespace RedHouse.Web
{
    public partial class AboutUs : PageBase
    {
        public List<RedHouseNews> NewsList { get; set; }
        private ILanguageService _languageService;
        protected void Page_Load(object sender, EventArgs e)
        {
            Initialize();
            if (Request.QueryString["id"] != null)
            {
                ucDetail.Visible = true;
                Guid id = new Guid(Request.QueryString["id"]);
                RedHouseNews news = NewsList.Where(n => n.Id == id).FirstOrDefault();
                ucDetail.News = news;
            }
        }

        private void Initialize()
        {
            ucDetail.Visible = true;
            _languageService = new LanguageService();

            NewsList = NewsService.Instance.GetAllNewsByGroup(RedHouseGroup.GroupList[0].Value)
                                   .Where(n => n.Category.ToLower().Equals("about"))
                                   .OrderByDescending(n => n.CreatedDate).ToList();
            if (Session["location"] != null)
            {
                int location = int.Parse(Session["location"].ToString());
                //NewsList = NewsList.Where(n => n.N == location).ToList();
            }

            Language language = null;
            if (Session["Culture"] != null && Session["Culture"].ToString() == "en-US")
            {
                language = _languageService.GetAllLanguage().Where(l => l.Description == "English").FirstOrDefault();
            }
            else
            {
                language = _languageService.GetAllLanguage().Where(l => l.Description != "English").FirstOrDefault();
            }

            if (language != null)
            {
                NewsList = NewsList.Where(n => n.NewsDetail.LangID == language.ID).ToList();
            }
            if (NewsList != null && NewsList.Count > 0)
            {
                ucDetail.News = NewsList[0];
            }
        }
    }
}